package com.easy.dfc.service;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.common.util.Utility;
import com.easy.dfc.entity.ParaAllProduct;
import com.easy.dfc.entity.ParaEnrollQuery;
import com.easy.dfc.mapper.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class DealerListService {

    @Resource
    private DfcAdvertisementMapper dfcAdvertisementMapper;

    @Resource
    private FactorySetMapper factorySetMapper;

    /**
     * 品牌馆/潮流馆-本周最大牌
     *
     * @param type
     * @return
     */
    public Result BestOnWeek(Integer type) {
        Result rt = new Result();
        List productList = factorySetMapper.BestOnWeek(type); //品牌馆/潮流馆-本周最大牌
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 品牌馆/潮流馆-今日我大牌
     *
     * @param pageIndex
     * @param pageSize
     * @param type
     * @return
     */
    public Result BestToday(Integer pageIndex, Integer pageSize, Integer type) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List factoryList = factorySetMapper.BestToday(pageIndex, pageSize, type); //品牌馆/潮流馆-今日我大牌
        if (factoryList == null) factoryList = new ArrayList();
        List ls = new ArrayList();
        for (int i = 0; i < factoryList.size(); i++) {
            Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
            int factoryId = (Integer) map.get("factoryId");
            List<Map<String, Object>> list = factorySetMapper.getNiceProductByFactoryId(factoryId);
            map.put("product", list);
            ls.add(map);
        }
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(ls);
        return rt;
    }
    /**
     * 品牌馆/潮流馆-今日我大牌更多。
     *
     * @param pageIndex
     * @param pageSize
     * @param type
     * @return
     */
    public Result BestTodayMore(Integer pageIndex, Integer pageSize, Integer type) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List factoryList = factorySetMapper.BestTodayMore(pageIndex, pageSize, type); //品牌馆/潮流馆-今日我大牌更多。
        if (factoryList == null) factoryList = new ArrayList();
        List ls = new ArrayList();
        for (int i = 0; i < factoryList.size(); i++) {
            Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
            int factoryId = (Integer) map.get("factoryId");
            List<Map<String, Object>> list = factorySetMapper.getNiceProductByFactoryId(factoryId);
            map.put("product", list);
            ls.add(map);
        }
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(ls);
        return rt;
    }

    /**
     * 品牌馆/潮流馆-今日我最爆
     *
     * @param pageIndex
     * @param pageSize
     * @param type
     * @return
     */
    public Result BestProductToday(Integer pageIndex, Integer pageSize, Integer type) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List productList = factorySetMapper.BestProductToday(pageIndex, pageSize, type); //品牌馆/潮流馆-今日我最爆
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 童品汇首页-商家列表
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result TPFactoryList(Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List factoryList = factorySetMapper.TPFactoryList(pageIndex, pageSize); //童品汇首页-商家列表
        if (factoryList == null) factoryList = new ArrayList();
        List ls = new ArrayList();
        for (int i = 0; i < factoryList.size(); i++) {
            Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
            int factoryId = (Integer) map.get("factoryId");
            List<Map<String, Object>> list = factorySetMapper.getNiceProductByFactoryId(factoryId);
            map.put("product", list);
            ls.add(map);
        }
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(ls);
        return rt;
    }

    /**
     * 童品汇首页-商品列表
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result TPBestProduct(String ageGroup, Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List productList = factorySetMapper.TPBestProduct(ageGroup, pageIndex, pageSize); //童品汇首页-商品列表
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 尾品汇首页-商家列表
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result WPFactoryList(Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List factoryList = factorySetMapper.WPFactoryList(pageIndex, pageSize); //尾品汇首页-商家列表
        if (factoryList == null) factoryList = new ArrayList();
        List ls = new ArrayList();
        for (int i = 0; i < factoryList.size(); i++) {
            Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
            int factoryId = (Integer) map.get("factoryId");
            List<Map<String, Object>> list = factorySetMapper.getNiceProductByFactoryId(factoryId);
            map.put("product", list);
            ls.add(map);
        }
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(ls);
        return rt;
    }

    /**
     * 尾品汇首页-商品列表
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result WPBestProduct(String ageGroup, Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List productList = factorySetMapper.WPBestProduct(ageGroup, pageIndex, pageSize); //童品汇首页-商品列表
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }


    /**
     * 尾品汇首页-今日抢购、明日预告
     *
     * @param pageIndex
     * @param pageSize
     * @param day
     * @return
     */
    public Result WPProduct(String ageGroup, Integer pageIndex, Integer pageSize, Integer day) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List productList = factorySetMapper.WPProduct(ageGroup, pageIndex, pageSize, day); //尾品汇首页-今日抢购、明日预告
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 天天焕新
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result DayDayProduct(Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List productList = factorySetMapper.DayDayProduct(pageIndex, pageSize); //天天焕新
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 好厂推荐
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result NiceFactory(Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex * pageSize;
        List factoryList = factorySetMapper.NiceFactory(pageIndex, pageSize); //尾品汇首页-商家列表
        if (factoryList == null) factoryList = new ArrayList();
        List ls = new ArrayList();
        for (int i = 0; i < factoryList.size(); i++) {
            Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
            int factoryId = (Integer) map.get("factoryId");
            List<Map<String, Object>> list = factorySetMapper.getNiceProductByFactoryId(factoryId);
            map.put("product", list);
            ls.add(map);
        }
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(ls);
        return rt;
    }

    public Result Banner(Integer type) {
        Result rt = new Result();
        List<Map<String, Object>> bannerList = dfcAdvertisementMapper.getMoreBanner(type);////顶部轮播
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(bannerList);
        return rt;
    }

    /**
     * 天天特价首页
     *
     * @param ageGroup
     * @return
     */
    public Result DaySpecialOffer(String ageGroup, Integer pageSize) {
        Result rt = new Result();
        Map<String, Object> map = new HashMap();
        Date now = new Date();
        if (pageSize < 4) pageSize = 4;
        List todayProductList = factorySetMapper.DaySpecialOffer(ageGroup, pageSize, now); //尾品汇首页-商家列表
        if (todayProductList == null) todayProductList = new ArrayList();
        List tomorrowProductList = factorySetMapper.DaySpecialOffer(ageGroup, pageSize, Utility.getDayAfter(now, 1)); //尾品汇首页-商家列表
        if (tomorrowProductList == null) tomorrowProductList = new ArrayList();
        map.put("todayList", todayProductList);
        map.put("tomorrowList", tomorrowProductList);
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(map);
        return rt;
    }

    /**
     * 天天特价更多
     *
     * @param para
     * @return
     */
    public Result DaySpecialOfferMore(ParaAllProduct para) {
        Result rt = new Result();
        Map<String, Object> map = new HashMap();
        Date now = new Date();
        List productList = factorySetMapper.DaySpecialOfferMore(para); //尾品汇首页-商家列表
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 订货会首页
     *
     * @param para
     * @return
     */
    public Result OrderMeeting(ParaEnrollQuery para) {
        Result rt = new Result();
        Map<String, Object> map = new HashMap();
        Date now = new Date();
        List productList = factorySetMapper.OrderMeeting(para); //订货会首页
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 订货会详情
     *
     * @param para
     * @return
     */
    public Result OrderMeetingDetail(ParaEnrollQuery para) {
        Result rt = new Result();
        Map<String,Object> map = new HashMap();
        Date now = new Date();
        Map<String,Object> productMap = factorySetMapper.OrderMeetingDetail(para); //订货会详情
        if(productMap == null)productMap = new HashMap<String,Object>();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productMap);
        return rt;
    }

    /**
     * 订货会详情商品
     *
     * @param para
     * @return
     */
    public Result OrderMeetingDetailProduct(ParaEnrollQuery para) {
        Result rt = new Result();
        Map<String,Object> map = new HashMap();
        Date now = new Date();
        List productList = factorySetMapper.OrderMeetingDetailProduct(para); //订货会详情
        if(productList == null)productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 聚爆款首页
     *
     * @param para
     * @return
     */
    public Result ImplosionList(ParaAllProduct para) {
        Result rt = new Result();
        Map<String, Object> map = new HashMap();
        Date now = new Date();
        List productList = factorySetMapper.ImplosionList(para); //聚爆款首页
        if (productList == null) productList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

    /**
     * 跳尾货场次
     *
     * @param para
     * @return
     */
    public Result JumpTailTime(ParaAllProduct para) {
        Result rt = new Result();
        Date now = new Date();
        List<Map<String,Object>> timeList = factorySetMapper.getJumpTailTime();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(timeList);
        return rt;
    }

    /**
     * 跳尾货场次列表
     *
     * @param para
     * @return
     */
    public Result JumpTailList(ParaAllProduct para) {
        Result rt = new Result();
        Date now = new Date();
        //List<Map<String, Object>> ls = new ArrayList<Map<String, Object>>();
        //List<Map<String,Object>> timeList = factorySetMapper.getJumpTailTime();
        //for (int i = 0; i < timeList.size(); i++) {
        //    Map tmap = (Map)timeList.get(i);
        //    Integer ltime = (Integer)tmap.get("ltime");
        //    Map<String, Object> map = new HashMap<String, Object>();
        //    map.put("ltime", ltime);
        //    para.setDay(ltime);
        //    List productList = factorySetMapper.getJumpTailList(para); //订货会详情
        //    if (productList == null) productList = new ArrayList();
        //    map.put("product", productList);
        //    ls.add(map);
        //}
        List<Map<String,Object>> productList = factorySetMapper.getJumpTailList(para); //订货会详情
        if (productList == null) productList = new ArrayList();

        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(productList);
        return rt;
    }

}
